<?php
if (isset($_SESSION['admin-login'])) {
	if (isset($param[2])) {
		if (isset($_SESSION['status-blog-edit'])) {
			echo "<p>".$_SESSION['status-blog-edit']."</p>";
			unset($_SESSION['status-blog-edit']);
		}
		$blog = db_result("SELECT * FROM blog WHERE id = ".intval($param[2]));
		?>
		<form action="<?php echo site()."/".$param[0]."/blog-edit-action/".$param[2] ?>" method="post" onsubmit="return validateBlog()">
			<input type="hidden" name="id" value="<?php echo $blog['id'] ?>" />
			Judul :<br><input type="text" name="judul" value="<?php echo $blog['judul'] ?>" /><br>
			Isi :<br><textarea name="textform"><?php echo $blog['textform'] ?></textarea><br>
			<input type="submit" name="post" id="post" value="Post" disabled="disabled" /><br>
			<a href="<?php echo site()."/".$param[0]."/blog" ?>">Cancel</a>
		</form>
		<script type="text/javascript">
		document.getElementById("post").removeAttribute("disabled");
		function validateBlog() {
			var body = document.getElementsByTagName("body")[0];
			var form = document.getElementsByTagName("form")[0];
			var judul = form["judul"].value;
			var textform = form["textform"].value;
			var status = document.getElementsByTagName("p")[0] || document.createElement("p");
			if (judul.length == 0 || textform.length == 0) {
				status.innerHTML = "Semua input harus diisi";
				body.insertBefore(status,form);
			} else {
				if (document.getElementsByTagName('p')[0])
					body.removeChild(document.getElementsByTagName('p')[0]);
				return true;
			}
			return false;
		}
		</script>
		<?php
	}
} else {
	$_SESSION['status-login'] = "Log in terlebih dahulu untuk melanjutkan";
	header("Location: ".site()."/".$param[0]."/login");
}
?>